﻿using System;

namespace DBMock.Builders.Attributes
{
    /// <summary>
    /// 字符串日期builder特性
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
    public class StrDateBuilderAttribute : BaseBuilderAttribute
    {
        /// <summary>
        /// 初始化StrDateBuilderAttribute
        /// </summary>
        /// <param name="minDate">最小日期</param>
        /// <param name="maxDate">最大日期</param>
        /// <param name="format">日期格式</param>
        public StrDateBuilderAttribute(string minDate = "1753.1.1", string maxDate = "9999.12.31",
            string format = "yyyyMMdd") : base(typeof(StrDateBuilder))
        {
            DateTime min;
            DateTime max;

            if (!DateTime.TryParse(minDate, out min))
            { min = new DateTime(1753, 1, 1); }

            if (!DateTime.TryParse(maxDate, out max))
            { max = new DateTime(9999, 12, 31); }

            para = new object[] { min, max, format };
        }
    }
}
